
agModeling.maternM=function(modelingObject){
	#fittedModel=inhomK(modelingObject,r=seq(0,200,length.out=700))
	fittedModel=inhompcf(modelingObject,maxt=100,bw=10)
	#here sigma2 represents sigma^2
	#if the nu is not given, do selection of the best nu
	if(modelingObject@nu==0){
		PlogG=best.matern.estK(attr(fittedModel,"K"), c(sigma2=3, alpha=10),
				rmax=attr(fittedModel,"rmax"),rmin=0,nu=c(Inf,0.25,0.5,1,4))
	}else{
		#PlogG=matern.estK(attr(fittedModel,"K"), c(sigma2=3, alpha=10),
		#		rmax=attr(fittedModel,"rmax"),rmin=0,nu=modelingObject@nu)
		PlogG=matern.estpcf(attr(fittedModel,"K"), c(sigma2=3, alpha=10),
				rmax=attr(fittedModel,"rmax"),rmin=10,nu=modelingObject@nu)
	}
	pnames=names(PlogG$par)
	#return the best nu if by model selection
	fittedModel@nu=attr(PlogG,"nu")
	
	p1=new("parameter",name=pnames[1],value=as.numeric(PlogG$par[1]))
	p2=new("parameter",name=pnames[2],value=as.numeric(PlogG$par[2]))
	mvalue=new("parameter",name="minivalue",value=as.numeric(PlogG$opt$value))
	cnv=new("parameter",name="covergent",value=as.numeric(PlogG$opt$convergence))
	
	prenames=names(fittedModel@parameters)
	fittedModel@parameters=c(fittedModel@parameters,p1,p2,mvalue,cnv)
	names(fittedModel@parameters)=c(prenames,pnames,"minivalue")
	#calculate pvalue for the parameters
	if(modelingObject@select & length(modelingObject@covr)!=0){
		#fittedModel=confi.inter(fittedModel,p1@value,p2@value)
	     fittedModel=confi.inter2(fittedModel)
	}
	if(!modelingObject@select){
		trend=predict(attr(fittedModel,"re.ppm"),type="trend")
		attr(fittedModel,"trend")=trend	
	}
	
	return(fittedModel)
}
